import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;


/**
 * 
 * @author Luke Brown
 *
 */
public class Button {
	private int cx;
	private int cy;
	private int width;
	private int height;
	private BufferedImage texture;
	private BufferedImage buttonImage;
	private Color textColor;
	private Screen gotoScreen;
	
	/**
	 * Class Constructor
	 * 
	 * @param centerX the x position of the center of the button
	 * @param centerY the y position of the center of the button
	 * @param width the width of the button
	 * @param height the height of the button
	 * @param texture the image which will be wrapped to make the image
	 * @param textColor the color of the text which will be written
	 * @param gotoScreen the Screen that the button goes to on click
	 */
	public Button(int centerX, int centerY, int width, int height, BufferedImage texture, Color textColor, Screen gotoScreen){
		this.cx=centerX;
		this.cy=centerY;
		this.width=width;
		this.height=height;
		this.texture=texture;
		this.buttonImage = new BufferedImage(this.width,this.height,BufferedImage.TYPE_INT_RGB);
		Graphics2D gimage = buttonImage.createGraphics();
		for(int i=0;i<this.buttonImage.getWidth();i+=texture.getWidth()){
			for(int j=0;j<this.buttonImage.getHeight();j+=texture.getHeight()){
				gimage.drawImage(this.texture, null, i, j);
			}
		}
		this.textColor=textColor;
		this.gotoScreen=gotoScreen;
	}
	
	/**
	 * The method that paints the button itself
	 * 
	 * @param g the BufferedImage Graphics2D to draw to
	 */
	public void paint(Graphics2D g){
		g.drawImage(getButtonImage(), null, this.cx+(this.width/2), this.cy+(this.height/2));
	}
	
	/**
	 * This method tells whether or not the mouse is over the button
	 * 
	 * @param mouseX the x coordinate of the mouse
	 * @param mouseY the y coordinate of the mouse
	 * @return true or false depending on the location of the mouse
	 */
	public boolean isAbove(int mouseX, int mouseY){
		if(mouseX>this.cx-this.width/2 && mouseX<this.cx+this.width/2 && mouseY>this.cy-this.height/2 && mouseY<this.cy+this.height/2){
			return true;
		}
		return false;
	}


	
	
	
	//Getters and Setters
	
	
	/**
	 * @return the cx
	 */
	public int getCx() {
		return cx;
	}

	/**
	 * @param cx the center x position to set
	 */
	public void setCx(int cx) {
		this.cx = cx;
	}

	/**
	 * @return the cy
	 */
	public int getCy() {
		return cy;
	}

	/**
	 * @param cy the center y position to set
	 */
	public void setCy(int cy) {
		this.cy = cy;
	}

	/**
	 * @return the width
	 */
	public int getWidth() {
		return width;
	}

	/**
	 * @param width the width to set
	 */
	public void setWidth(int width) {
		this.width = width;
	}

	/**
	 * @return the height
	 */
	public int getHeight() {
		return height;
	}

	/**
	 * @param height the height to set
	 */
	public void setHeight(int height) {
		this.height = height;
	}

	/**
	 * @return the texture
	 */
	public BufferedImage getTexture() {
		return texture;
	}

	/**
	 * @param texture the texture to set
	 */
	public void setTexture(BufferedImage texture) {
		this.texture = texture;
	}

	/**
	 * @return the textColor
	 */
	public Color getTextColor() {
		return textColor;
	}

	/**
	 * @param textColor the textColor to set
	 */
	public void setTextColor(Color textColor) {
		this.textColor = textColor;
	}

	/**
	 * @return the gotoScreen
	 */
	public Screen getGotoScreen() {
		return gotoScreen;
	}

	/**
	 * @param gotoScreen the gotoScreen to set
	 */
	public void setGotoScreen(Screen gotoScreen) {
		this.gotoScreen = gotoScreen;
	}

	/**
	 * @return the buttonImage
	 */
	public BufferedImage getButtonImage() {
		return buttonImage;
	}

	/**
	 * @param buttonImage the buttonImage to set
	 */
	public void setButtonImage(BufferedImage buttonImage) {
		this.buttonImage = buttonImage;
	}
}
